//
//  GroupDesTableViewController.m
//  YeDian
//
//  Created by Mac on 14-7-22.
//  Copyright (c) 2014年 Mac. All rights reserved.
//

#import "GroupDesTableViewController.h"

@interface GroupDesTableViewController ()

@property (nonatomic, strong) NSDictionary *infoDic;

@end

@implementation GroupDesTableViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (IBAction)backAtion:(UIButton *)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    [self initData];
}

- (void)initData{
    
    //@[_infoDic[@"groupNO"],_infoDic[@"groupDistance"],_infoDic[@"barsName"],_infoDic[@"groupHoster"],_infoDic[@"createTime"]];
    NSArray *keyArr = @[@"imageUrl",@"groupNO",@"groupDistance",@"barsName",@"groupHoster",@"createTime",@"des",@"groupMembers"];
    NSArray *valueArr = @[@"http://那张群资料的图片网址",@"48545454",@"1.75km",@"上海外滩群组",@"大头小哥小",@"2013-10-09",@"最有趣味的群组认识新朋友",@"群成员"];
    self.infoDic = [NSDictionary dictionaryWithObjects:valueArr forKeys:keyArr];
    [self.tableView reloadData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section==0) {
        if (indexPath.row==0) {
            //群组资料
            return 70;
        }
        else if (indexPath.row==6){
            
            //群介绍
            NSString *des = _infoDic[@"des"];
            CGSize size = [des sizeWithFont:[UIFont systemFontOfSize:14.0] constrainedToSize:CGSizeMake(270, 1000) lineBreakMode:0];
            
            return 25+size.height+5;
        }
        else if (indexPath.row==7){
            
            //群组成员
            return 57;
        }
        else{
            
            return 44;
        }
    }
    else{
        
        return 44;
    }
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{


    if (section==0) {
        return 8;
    }
    else{
        return 1;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        if (indexPath.row==0) {
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell0" forIndexPath:indexPath];
            UIImageView *imageV = (UIImageView *)[cell.contentView viewWithTag:1];
            imageV.image = [UIImage imageNamed:@"详情图片2.png"];
            return cell;
        }
        else if(indexPath.row==6){
            
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell2" forIndexPath:indexPath];
            UILabel *desLab = (UILabel *)[cell.contentView viewWithTag:1];
            NSString *des = _infoDic[@"des"];
            CGSize size = [des sizeWithFont:[UIFont systemFontOfSize:14.0] constrainedToSize:CGSizeMake(270, 1000) lineBreakMode:0];
            [desLab setFrame:CGRectMake(20, 25, size.width, size.height)];
            desLab.text = des;
            return cell;
        }
        else if(indexPath.row==7){
            
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell3" forIndexPath:indexPath];
            for (UIView *view in cell.contentView.subviews) {
                if (view.tag>=10) {
                    [view removeFromSuperview];
                }
            }
            
            for (int i = 0; i<9; i++) {
                UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(10+34*i, 23, 30, 30)];
                view.backgroundColor = [UIColor redColor];
                view.tag = i+10;
                [cell.contentView addSubview:view];
            }
            return cell;
        }
        else{
            
            NSArray *nameArr = @[@"群号码",@"距离",@"夜店",@"群主",@"创建时间"];
            NSArray *valueArr = @[_infoDic[@"groupNO"],_infoDic[@"groupDistance"],_infoDic[@"barsName"],_infoDic[@"groupHoster"],_infoDic[@"createTime"]];
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1" forIndexPath:indexPath];
            UILabel *nameLab = (UILabel *)[cell.contentView viewWithTag:1];
            nameLab.text = nameArr[indexPath.row-1];
            
            UILabel *valueLab = (UILabel *)[cell.contentView viewWithTag:2];
            valueLab.text = valueArr[indexPath.row-1];
            return cell;
            
        }
    }
    else{
        
        
        //申请加入
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell4" forIndexPath:indexPath];
        return cell;
    }
 
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
